<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>收货地址</title>
    <link rel="stylesheet" href="css/amazeui.min.css" />
    <link rel="stylesheet" href="css/app.css" />
    <link rel="stylesheet" href="css/style.css" />
    <style>

    </style>
</head>

<body>
    <header class="am-u">
        <div class="am-u-sm-12 head_nav" style="margin:0;">
            <div class="am-u-sm-2 am-vertical-align">
                <a href="mine.html">
                    <img src="img/return@2x.png" class="am-vertical-align-middle" alt="">
                </a>
            </div>
            <div class="am-u-sm-8 head_text">
                收货地址
            </div>
            <div class="am-u-sm-2">
            </div>
        </div>
    </header>
    <div style="clear:both"></div>
    <div class="am-u myDeviceLists">
        <div id="mymod">
            <p style="text-align:center;margin-top:20px;font-size:20px;">加载中</p>
        </div>
        <button class="bulink" style="width:85%;">新增收货地址</button>
    </div>
    <div style="clear: both;"></div>

    <script src="js/jquery.min.js" type="text/javascript"></script>

</body>
<script>
    $(function () {
        var token1 = sessionStorage['token'];;
        var method = "Shop|shop_user_address";
        $.ajax({
            type: 'POST',
            url: "http://www.rice.com/app/api/h5_access",
            contentType: "application/x-www-form-urlencoded; charset=utf-8",
            datatype: "JSON",
            data: {
                token: token1,
                method: method,
            },
            success: function (data) {
                var data1 = JSON.parse(data);
                console.log(data1);
                var str = data1.data.list;
                total = data1.data.total;
                var html = "";
                if (total >= 1) {
                    for (var i = 0; i < str.length; i++) {
                        var o = str[i];
                        if (o.status == 1) {

                            html +=
                                `
                        <div class="mymod" >
                            <p style="display:none;" class="status">${o.status}</p>
                            <p class="mymt1">
                                <span class="mymt1sd">
                                    <span class="mymt1s1">默认</span>
                                    <span class="mymt1s2">收货人：<span class="mymt1s4">${o.receiver_name}</span></span>
                                </span>
                                <span class="mymt1s3">${o.receiver_phone}</span>
                            </p>
                            <p class="mymt2">收货地址：
                                <span class="mymd1">${o.province}</span>
                                <span class="mymd2">${o.city}</span>
                                <span class="mymd3">${o.district}</span>
                                <span class="mymd4">${o.address}</span>
                            </p>
                            <a onclick="my_address(this)" data-orderId="${o.id}" class="mymlink"><img src="img/modify.png" alt="" class="mymtpic" /></a>
                        </div>
                        `;
                        } else {
                            html +=
                                `
                        <div class="mymod">
                            <p style="display:none;" class="status">${o.status}</p>
                            <p class="mymt1">
                                <span class="mymt1sd">
                                    <span class="mymt1s2">收货人：<span class="mymt1s4">${o.receiver_name}</span></span>
                                </span>
                                <span class="mymt1s3">${o.receiver_phone}</span>
                            </p>
                            <p class="mymt2">收货地址：
                                <span class="mymd1">${o.province}</span>
                                <span class="mymd2">${o.city}</span>
                                <span class="mymd3">${o.district}</span>
                                <span class="mymd4">${o.address}</span>
                            </p>
                            <a onclick="my_address(this)" data-orderId="${o.id}" class="mymlink"><img src="img/modify.png" alt="" class="mymtpic" /></a>
                        </div>
                        `;
                        }
                    }
                }
                $('#mymod').html(html);
            }
        })

        // 新增收货地址
        $('.bulink').on('click', function () {
            window.location.href = "my_address1.html";
        })
    });

    function my_address(obj) {
        var _this = obj
        var $orderId = $(_this).attr('data-orderId'); //id
        var $name = $(_this).siblings('.mymt1').find('.mymt1s4').html(); //姓名
        var $phone = $(_this).siblings('.mymt1').find('.mymt1s3').html(); //手机号
        var $province = $(_this).siblings('.mymt2').find('.mymd1').html(); //省
        var $city = $(_this).siblings('.mymt2').find('.mymd2').html(); //市
        var $district = $(_this).siblings('.mymt2').find('.mymd3').html(); //区
        var $address = $(_this).siblings('.mymt2').find('.mymd4').html(); //详情
        var $status = $(_this).siblings('.status').html(); //是否默认

        console.log($orderId)
        console.log($name)
        console.log($phone)
        console.log($province)
        console.log($city)
        console.log($district)
        console.log($address)
        console.log($status)
        sessionStorage.setItem("address_id", $orderId);
        sessionStorage.setItem("name", $name);
        sessionStorage.setItem("phone", $phone);
        sessionStorage.setItem("province", $province);
        sessionStorage.setItem("city", $city);
        sessionStorage.setItem("district", $district);
        sessionStorage.setItem("address", $address);
        sessionStorage.setItem("status", $status);
        window.location.href = "my_address.html"
    }
</script>

</html>